﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using AForge.Neuro;



namespace Projekt1SN
{
    public partial class Form1 : Form
    {
        private INeuralNetwork neuralNetwork;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void loadConfigButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory() + "Examples";
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                StreamReader stream = new StreamReader(openFileDialog1.FileName);
                string[] configStrings = stream.ReadToEnd().ToLower().Split(new char[] { '\n' }, int.MaxValue);
                neuralNetwork = FileReader.ProcessConfigFile(configStrings);
            }
        }

        private void trainButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                StreamReader stream = new StreamReader(openFileDialog1.FileName);
                string trainString = stream.ReadToEnd().ToLower();
                neuralNetwork.LoadTrainingData(trainString);
                neuralNetwork.Learn(showErrorsCheckBox.Checked, saveToFileCheckBox.Checked);
            }
        }

        private void runButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                StreamReader stream = new StreamReader(openFileDialog1.FileName);
                string testString = stream.ReadToEnd().ToLower();
                neuralNetwork.LoadInput(testString);
                
                double[][] output = neuralNetwork.Run();
                double[][] input = neuralNetwork.ShowInput();

                neuralNetwork.PrintInputOutput(input, output);
            }
        }

        private void printButton_Click(object sender, EventArgs e)
        {
            neuralNetwork.PrintWeights();
        }   
    }
}
